# -*- coding: UTF-8 -*-

# Créé par Néhémie en 2020


import time
import tweepy
import sys


supprimes = []

# Taille des sélections
taille_des_requettes=100

auth = tweepy.auth.OAuthHandler(
        consumer_key='CLEF',
        consumer_secret='SECRET')
auth.set_access_token(
        'TOKEN1',
        'TOKEN2')

# the following dictionaries etc aren't strictly needed for this
# but useful for your own more in-depth apps.

api=tweepy.API(auth_handler=auth)


print ("Loading followers..")
followers = []
for follower in tweepy.Cursor(api.followers).items(taille_des_requettes):
    followers.append(follower)

print ("Found %s followers, finding friends.." % len(followers))
friends = []
for friend in tweepy.Cursor(api.friends).items(taille_des_requettes):
    friends.append(friend)

# creating dictionaries based on id's is handy too

friend_dict = {}
for friend in friends:
    friend_dict[friend.id] = friend

follower_dict = {}
for follower in followers:
    follower_dict[follower.id] = follower

# now we find all your "non_friends" - people who don't follow you
# even though you follow them.



non_friends = [friend for friend in friends if friend.id not in follower_dict]

# Amis essentiels
liste_essentielle = ["Siphano","Olydri_Fournier","nexoggs24"]



# CREATION DU FICHIER PSEUDOS
f = open('Pseudos.txt','w')




# double check, since this could be a rather traumatic operation.

print ("Unfollowing %s non-following users.." % len(non_friends))

for nf in non_friends:
    if nf.name != "Siphano" and  nf.name != "Olydri_Fournier" and  nf.name != "nexoggs24":


        try:
            nf.unfollow()

        except:
            print ("  .. failed, sleeping for 5 seconds and then trying again.")
            time.sleep(5)
            nf.unfollow()
        print ("OK - Deleted")
        supprimes.append(nf.name)



